<template>
	<view>
		<head-navbar :back="true">
			<view>
				<text>创建子账号</text>
			</view>
		</head-navbar>
		<view class="content">
			<view class="box">
				<view class="title">
					<view class="text">数量</view>
				</view>
				<view class="select"><input v-model="count" type="text" placeholder="请输入数量" /></view>
				<!-- <view class="select">创建每个子账户需消耗1WDT</view> -->
				<view class="down">剩余可创建子账号数量：{{downCount}}</view>
			</view>
			<button class="btn" @click="submit">确认</button>
		</view>
	</view>
</template>

<script>
	import * as api from '../../api/group/index'
	export default{
		data() {
			return {
				count:'',
				downCount:0,
				numTest:/^[1-9]\d*$/
			}
		},
		onLoad(){
			this.getUserEstablish()
		},
		methods:{
			getUserEstablish(){
				api.getUserEstablish({}).then(res=>{
					 this.downCount = res.data.dataBody
				}).catch(err=>{
					
				})
			},
			submit(){
				if(this.count == ''){
					uni.showToast({
						title:'数量不能为空',
						icon:'none'
					})
					return
				}
				if(this.count == 0){
					uni.showToast({
						title:'数量不能为0',
						icon:'none'
					})
					return
				}
				if(!this.numTest.test(this.count)){
					uni.showToast({
						title:'数量必须为整数',
						icon:'none'
					})
					return
				}
				if(this.count > this.downCount){
					uni.showToast({
						title:'超出可创建数量',
						icon:'none'
					})
					return
				}
				api.addChildUser({request:{count:this.count}}).then(res=>{
					uni.showToast({
						title:'创建成功',
						icon:'none'
					})
					var that = this
					setTimeout(function(){
						// that.$api.prePage().status = 'loading'
						// that.$api.prePage().list = []
						// that.$api.prePage().getChildUserByUserCode()
						uni.navigateBack({
							delta:1,
						})
					},1000)
				}).catch(err=>{
					
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
  .content{
	  padding: 30rpx;
	  .box{
		  background: #FFFFFF;
		  border-radius: 20rpx;
		  padding: 30rpx;
		  .title{
			  display: flex;
			  align-items: center;
			  .text{
				  flex: none;
				  font-size: 36rpx;
				  margin-right: 20rpx;
			  }
		  }
		  input{
		  	   font-size: 26rpx;
		  }
		  .select{
			  margin-top: 30rpx;
			  color: #9A9A9A;
			  font-size: 26rpx;
			  padding-bottom: 20rpx;
			  border-bottom: 1rpx solid #f4f4f4;
		  }
		  .down{
			  margin-top: 30rpx;
			  color: #FF5C02;
			  font-size: 26rpx;
		  }
	  }
	  .btn{
		  background: #FF5C02;
		  border-radius: 100rpx;
		  color: #FFFFFF;
		  margin-top: 30rpx;
	  }
		.cancel-btn {
			background-color: #dbdbdb;
			border-radius: 100rpx;
			margin-top: 50rpx;
			color: #FFFFFF;
		}
  }
</style>
